/***************************************************************************
 *   Copyright (C) 2009 by maarten,,,   *
 *   maarten@maarten-laptop   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef DRAWCGPANEL_H
#define DRAWCGPANEL_H

#include <QWidget>
#include <QColor>

#include "scenemanager/scenemanager.h"
#include "utils/matrix.h"

// forward class defs
namespace scene { 
    class SceneManager;
    class Camera;
    class PointLight;
    class SubScene;
    class Shape;
}

namespace object {
    class ObjectList;
    class Plane;
    class Vertex;
}

namespace draw {

class RayTracer;
class Rasterizer;
class FloatMatrix;


/**
	@author maarten,,, <maarten@maarten-laptop>
*/
class CgPanel : public QWidget
{

Q_OBJECT

public:
    CgPanel(QWidget *parent);
    ~CgPanel();

    void readSceneFile();
    void paintEvent(QPaintEvent *event);
    void setBgColor ( float r, float g, float b );
    
    void drawPixel(int x, int y, QColor color);

    QColor bgColor() const{return m_bgColor;}
    void cleanScreen();
    
    // rasterizing
    void walkThroughScene(scene::SubScene * temp);

public slots:
    void startRaytracing();
    void startRasterizing();
    void saveImage();
    

private:
    scene::SceneManager * m_sceneMgr; // deleted in mainscreen
    QColor m_bgColor, m_frontColor;
    QPixmap m_pixMap;

    scene::Camera *m_camera;

    int m_width;
    int m_height;
    
    float xaverage;
    float yaverage;
    float zaverage;
    RayTracer * m_rayTracer;
    Rasterizer *m_rasterizer;
    
    // temp vars for rasterization
    FloatMatrix * m_currentTransform;
    int m_nrOfTransformations;
    QVector<object::Plane*> m_planesToDraw;
    void prepareScene(); // adds planes to draw
    
    object::Vertex* calcColor(object::Vertex * surfNorm, object::Vertex *
                                                                    position);
   

};

} // end namespace draw

#endif
